package com.zc.framework.shiro;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * Created by zc on 2016/8/30.
 */
public class RealmEventManager {

    private static RealmEventManager instance = new RealmEventManager();

    private List<RealmEventListener> registedRealms = Lists.newLinkedList();

    public static RealmEventManager getInstance(){
        return instance;
    }

    public void registReamlInstance(RealmEventListener listener){
        this.registedRealms.add(listener);
    }

    public void unRegistRealmInstance(RealmEventListener listener){
        this.registedRealms.remove(listener);
    }


    public void clearCachedAuthorizationInfo(String principal){
        for (RealmEventListener item: this.registedRealms) {
            item.clearCachedAuthorizationInfo(principal);
        }
    }

    public void clearAllCachedAuthorizationInfo(){
        for (RealmEventListener item: this.registedRealms) {
            item.clearAllCachedAuthorizationInfo();
        }
    }
}
